//package org.dromara.web.controller;
//
//import cn.dev33.satoken.annotation.SaIgnore;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.dromara.common.core.domain.R;
//import org.dromara.common.mybatis.core.page.PageQuery;
//import org.dromara.common.mybatis.core.page.TableDataInfo;
//import org.dromara.web.domain.bo.MarketBo;
//import org.dromara.web.domain.vo.MarketVo;
//import org.dromara.web.service.impl.ApiServiceImpl;
//import org.springframework.ai.chat.client.ChatClient;
//import org.springframework.ai.chat.messages.Message;
//import org.springframework.ai.chat.messages.UserMessage;
//import org.springframework.ai.chat.model.ChatResponse;
//import org.springframework.ai.chat.prompt.Prompt;
//import org.springframework.ai.chat.prompt.SystemPromptTemplate;
//import org.springframework.ai.ollama.OllamaChatModel;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.core.io.Resource;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@Validated
//@Slf4j
//@RestController
//@RequiredArgsConstructor
//@RequestMapping("/ollama")
//@SaIgnore
//public class OllamaChatController {
//
//    private final OllamaChatModel chatModel;
//
//    private final ApiServiceImpl apiService;
//
//    @Value("classpath:/prompts/system-message.st")
//    private Resource resource;
//
//
//    @GetMapping("/commonChat")
//    public R<String> chat(String message) {
//        ChatResponse call = chatModel.call(new Prompt(message));
//        return R.ok(call.getResult().getOutput().getText());
//    }
//
//    @GetMapping("/promptChat")
//    public R<String> chat2(@RequestParam String message, @RequestParam String name,
//                           MarketBo bo, PageQuery pageQuery,
//                           @RequestParam(required = false) String sortField,
//                           @RequestParam(required = false) String sortOrder) {
//        // 1. 将用户输入的消息封装为一个UserMessage对象
//        UserMessage userMessage = new UserMessage(message);
//        // 2.使用系统资源初始化 SystemPromptTemplate
//        SystemPromptTemplate systemPromptTemplate = new SystemPromptTemplate(resource);
//        // 3.通过模版文件和参数创建系统消息
//        Map<String, Object> params = new HashMap<>();
//        bo.setSortField(sortField);
//        bo.setSortOrder(sortOrder);
//        TableDataInfo<MarketVo> data = apiService.queryPageList(bo, pageQuery);
//        params.put("data", data.getRows());
//        params.put("name", name);
//        Message systemMessage = systemPromptTemplate.createMessage(params);
//        // 4.将用户的消息和系统的消息封装为一个车提示词对象 Prompt
//        Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
//        // 调用模型进行对话
//        ChatResponse call = ChatClient.create(chatModel).prompt(prompt).call().chatResponse();
//        return R.ok(call.getResult().getOutput().getText());
//    }
//
//}
